#include "../../source/server.hpp"

void OnConnected(const PtrConnection &conn)
{
    logMessage(DEBUG,"new connection: %p",conn.get());
}
void OnClose(const PtrConnection &conn)
{
    logMessage(DEBUG,"close connection: %p",conn.get());
}
void OnMessage(const PtrConnection &conn,Buffer* buf)
{
    logMessage(DEBUG,"recv a message:%s",buf->ReadPosition());
    buf->MoveReadOffest(buf->ReadAbleSize());
    std::string str = "I sent you a message";
    conn->Send(str.c_str(),str.size());
    conn->ShutDown();
}
int main()
{
    TcpServer server(8500);
    server.SetThreadCount(2);
    //server.EnableInactiveRelease(10);
    server.SetClosedCallback(OnClose);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);
    server.Start();
    return 0;
}